<?php

namespace App\Http\Middleware;
use Illuminate\Support\Facades\Redis;

use Closure;

class checkLoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->header('authorization')!==null){
            $token = $request->header('authorization');
            $key = explode('.',$token);
            $data = Redis::get($key[0]);
            if($data){
                // $request->attributes->add(json_decode($data,true));
                return $next($request);
            }
        }
        $return['code'] = 403;
        $return['data'] = [];
        $return['msg'] = '登录已过期';
        return response()->json($return,403);
    }
}
